package dingding.使用线程池;

import java.util.concurrent.*;

public class CompletableFutureDemo {

    private final static int AVALABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();

    private final static ThreadPoolExecutor pool = new ThreadPoolExecutor(AVALABLE_PROCESSORS,
            AVALABLE_PROCESSORS * 2, 1, TimeUnit.MINUTES,
            new LinkedBlockingDeque<>(5),
            new ThreadPoolExecutor.CallerRunsPolicy());

    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {

        CompletableFuture<String> future = new CompletableFuture();

        pool.execute(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            future.complete("返回结果");
        });
        System.out.println(future.get(10, TimeUnit.SECONDS));
        System.out.println("main被阻塞");
    }
}
